<template>
	<view class="free-box-item">
		<view class="magic-bag-container" @click="$emit('handleClick')">
			<view class="image-wrapper">
				<image class="magic-img" :src="mianImg" mode="aspectFit"></image>
			</view>
			<view class="box-info">
				<text class="title ellipsis">{{value.title}}</text>
				<text class="desc ellipsis">{{value.desc}}</text>
				<view class="box-bottom">
					<view class="box-bottom-left">
						<!-- #ifdef APP-NVUE -->
						<image class="unit-icon" src="@/static/image/coin-icon.png" mode="widthFix"></image>
						<!-- #endif -->
						<!-- #ifndef APP-NVUE -->
						<text class="unit-icon"></text>
						<!-- #endif -->
						<view class="price">
							<text class="price-text">{{value.new_price}}</text>
							<text class="old_price">{{value.price}}</text>
						</view>
					</view>
				</view>
				<view class="image-list-wrapper">
					<image v-for="(item,index) in value.manyGoods.slice(0,5)" :key="index" class="product-img"
						:src="goodsImage(item.goods_image+'?x-oss-process=image/resize,w_68,m_lfit')" mode="aspectFit">
					</image>
				</view>
				<view class="box-status">
					<image v-if="value.state==2" src="/static/image/opened-box.png" mode="widthFix"></image>
					<image v-else-if="value.state==3" src="/static/image/overdue-box.png" mode="widthFix"></image>
				</view>
			</view>

		</view>
		<view class="deadline">
			有效日期：{{getSplitDate(value.start_time)}}-{{getSplitDate(value.end_time)}}
		</view>
	</view>
</template>

<script>
	import util from '@/common/js/util.js';
	export default {
		props: {
			value: {
				type: Object,
				required: true
			}
		},
		computed: {
			manyPeople() {
				return this.value.manyOrder;
			},
			mianImg() {
				return util.img(this.value.list_img + "?x-oss-process=image/resize,h_270,w_270,m_fixed");
			},
		},
		methods: {
			goodsImage(img) {
				return util.img(img);
			},
			getSplitDate(time) {
				return time.split(' ')[0].replace(/-/g, '.')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ellipsis {
		/* #ifndef APP-NVUE */
		white-space: nowrap;
		/* #endif */
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.ellipsis-line2 {
		text-overflow: ellipsis;
		overflow: hidden;
		/* #ifndef APP-NVUE */
		display: -webkit-box; //弹性盒模型
		-webkit-box-orient: vertical; //上下垂直
		-webkit-line-clamp: 2; //自定义行数
		/* #endif */

	}

	.free-box-item {
		background-color: #FFFFFF;
		border-radius: 30rpx;
		margin-bottom: 14rpx;

		.magic-bag-container {
			padding: 19rpx 26rpx 31rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: row;

			.image-wrapper {
				flex-shrink: 0;
				position: relative;
				width: 214rpx;
				height: 214rpx;

				.magic-img {
					height: 100%;
					width: 100%;
				}
			}

			.box-info {
				flex: 1;
				margin-right: 10rpx;
				margin-left: 13rpx;
				padding-top: 6rpx;
				padding-right: 10rpx;
				position: relative;

				.title {
					width: 400rpx;
					font-size: 30rpx;
					line-height: 30rpx;
					height: 30rpx;
					font-weight: 500;
					color: #111111;
					display: block;
				}

				.desc {
					width: 400rpx;
					// margin-top: 21rpx;
					// margin-bottom: 22rpx;
					font-size: 21rpx;
					line-height: 24rpx;
					// height: 56rpx;
					color: #999999;
					margin: 12rpx 0 14rpx 0;
				}

				.box-bottom {
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;

					.box-bottom-left {
						display: flex;
						justify-content: flex-start;
						flex-direction: row;
						align-items: center;

						.unit-icon {
							width: 40rpx;
							height: 40rpx;
							/* #ifndef APP-NVUE */
							background: url("~@/static/image/coin-icon.png");
							background-size: 100% 100%;
							/* #endif */
						}

						.price {
							font-size: 33rpx;
							line-height: 26rpx;
							color: #111111;
							font-weight: bold;

							.price-text {
								text-align: left;
							}

							.old_price {
								text-decoration: line-through;
								font-size: 22rpx;
								line-height: 17rpx;
								color: #999;
								margin-left: 14rpx;
							}
						}

					}
				}

				.image-list-wrapper {
					// padding-top: 22rpx;
					// border-top: 1rpx solid #ECECEC;
					margin-top: 19rpx;
					display: flex;
					flex-direction: row;

					.product-img {
						margin-right: 8rpx;
						height: 68rpx;
						width: 68rpx;
						/* #ifndef APP-NVUE */
						box-sizing: border-box;
						/* #endif */

						&:last-child {
							margin-right: 0;
						}
					}
				}


				.box-status {
					position: absolute;
					top: 18rpx;
					right: 14rpx;
					width: 116rpx;
					height: 116rpx;

					&>image {
						width: 100%;
					}
				}
			}

		}


		.deadline {
			height: 59rpx;
			line-height: 59rpx;
			font-size: 21rpx;
			color: #333333;
			padding-left: 28rpx;
			border-top: 1px dashed #DADADA;
		}
	}
</style>
